package com.lab.system.service.impl;

import com.lab.system.domain.AppointmentViolationRecord;
import com.lab.system.domain.Reservations;
import com.lab.system.mapper.AppointmentViolationRecordMapper;
import com.lab.system.mapper.ReservationsMapper;
import com.lab.system.service.IAppointmentViolationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 用户违规记录Service业务层处理
 *
 * @author cf
 * @date 2025-02-11
 */
@Service
public class AppointmentViolationRecordServiceImpl implements IAppointmentViolationRecordService {
    @Autowired
    private AppointmentViolationRecordMapper appointmentViolationRecordMapper;
    @Autowired
    private ReservationsMapper reservationsMapper;

    /**
     * 查询用户违规记录
     *
     * @param id 用户违规记录主键
     * @return 用户违规记录
     */
    @Override
    public AppointmentViolationRecord selectAppointmentViolationRecordById(Long id) {
        return appointmentViolationRecordMapper.selectAppointmentViolationRecordById(id);
    }

    /**
     * 查询用户违规记录列表
     *
     * @param appointmentViolationRecord 用户违规记录
     * @return 用户违规记录
     */
    @Override
    public List<AppointmentViolationRecord> selectAppointmentViolationRecordList(AppointmentViolationRecord appointmentViolationRecord) {
        return appointmentViolationRecordMapper.selectAppointmentViolationRecordList(appointmentViolationRecord);
    }

    /**
     * 新增用户违规记录
     *
     * @param appointmentViolationRecord 用户违规记录
     * @return 结果
     */
    @Override
    public int insertAppointmentViolationRecord(AppointmentViolationRecord appointmentViolationRecord) {
        // 插入用户违规记录，同时修改预约记录状态为-已取消
        Reservations reservations = reservationsMapper.selectReservationsById(appointmentViolationRecord.getAppointmentId());
        reservations.setStatus(4L);
        reservationsMapper.updateReservations(reservations);
        return  appointmentViolationRecordMapper.insertAppointmentViolationRecord(appointmentViolationRecord);
    }

    /**
     * 修改用户违规记录
     *
     * @param appointmentViolationRecord 用户违规记录
     * @return 结果
     */
    @Override
    public int updateAppointmentViolationRecord(AppointmentViolationRecord appointmentViolationRecord) {
        return appointmentViolationRecordMapper.updateAppointmentViolationRecord(appointmentViolationRecord);
    }

    /**
     * 批量删除用户违规记录
     *
     * @param ids 需要删除的用户违规记录主键
     * @return 结果
     */
    @Override
    public int deleteAppointmentViolationRecordByIds(Long[] ids) {
        return appointmentViolationRecordMapper.deleteAppointmentViolationRecordByIds(ids);
    }

    /**
     * 删除用户违规记录信息
     *
     * @param id 用户违规记录主键
     * @return 结果
     */
    @Override
    public int deleteAppointmentViolationRecordById(Long id) {
        return appointmentViolationRecordMapper.deleteAppointmentViolationRecordById(id);
    }

    @Override
    public List<Long> countUser5() {
        return appointmentViolationRecordMapper.countUser5();
    }
}
